<%@page pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.messager.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
<head>
<jsp:include page="../admin_head.jsp">
	<jsp:param value="用户信息" name="title" />
</jsp:include>
</head>
<body>
	<div class="container-fluid">
		<div class="row" >
			<div class="col-md-2"></div>
			<div class="col-md-8">
				<div class="panel panel-success" align="center">
				<div class="panel-heading">
				<h1 >课堂教学质量评价系统</h1><br/>当前用户:${user.nickName }&nbsp;&nbsp;&nbsp;
						当前用户角色：${user.userRole }
				&nbsp;&nbsp;&nbsp;&nbsp;<a href="userlist.action?userId=${user.id }"><button class="btn btn-sm btn-success">首页</button></a>
						<a href="${pageContext.request.contextPath }/user/user.action"> <button class="btn btn-sm btn-danger" > <B> 退出登录 </B> </button> </a></div>
				</div>
			
			<jsp:include page="../user/admin_nav.jsp">
					<jsp:param value="用户界面" name="title" />
				</jsp:include>
				<div class="panel panel-success">
				<div class="panel panel-primary" style="margin-left: 300px;width:900px;margin-top:15px">
					<div class="panel-heading">
						<h3 class="panel-title" id="h1">课程列表</h3>
						<h3 class="panel-title" id="h2" style="display:none">学生列表</h3>
						<h3 class="panel-title" id="h3" style="display:none">评价详情列表</h3>
					</div>
					<div class="panel-body">
						
						<table class="table table-hover table-bordered" style="margin-top: 20px" id="user_table">
							<thead>
								<tr align="center" style="font-weight: bold">
									<td>序号</td>
									<td>课程名称</td>
									<td>课程简介</td>
									<c:if test="${user.userType eq 1 }">
									<td>教师姓名</td>
									<td>教师简介</td>
									<td>课程状态</td>
									</c:if>
									<c:if test="${user.userType eq 2 }">
									<td>学生名单</td>
									</c:if>
									<c:if test="${user.userType eq 3 }">
									<td>评价总人数</td>
									<td>分数</td>
									<td>操作</td>
									</c:if>
								</tr>
							</thead>
							<tbody>
								<c:if test="${classList ne null}">
								<c:forEach items="${classList}" var="classvo" varStatus="vs">
										<tr align="center">
											<td>${vs.count }</td>
											<td>${classvo.name }</td>
											<td>${classvo.class_introduce }</td>
											<c:if test="${user.userType eq 1 }">
											<td>${classvo.teacherName }</td>
											<td>${classvo.tea_introduce }</td>
											<td>
											<c:if test="${classvo.class_status==1 }">在修</c:if>
											<c:if test="${classvo.class_status==2 }">已修</c:if>
											</td>
											</c:if>
											<c:if test="${user.userType eq 2 }">
											<td>
											<button id="stuList" class="btn btn-info" onclick="getStus(${classvo.id})">学生名单</button>
											<button id="stuList" class="btn btn-info" onclick="getAllEvaInfo(${classvo.id})">评价情况</button>
											</td>
											</c:if>
											<c:if test="${user.userType eq 3 }">
											<td>${classvo.allEvaPeople }</td>
											<td>${classvo.aveScore }</td>
											<td>
											<button id="stuList" class="btn btn-info" onclick="getAllEvaInfo(${classvo.id})">评价情况</button>
											</td>
											</c:if>
										</tr>
								</c:forEach>
								</c:if>
							<tr>
							<c:if test="${user.userType eq 1 }">
							<td colspan="6"><button class="btn btn-default" onClick="location.href='userlist.action?userId=${user.id}'">返回</button></td>
							</c:if>
							<c:if test="${user.userType eq 2 }">
							<td colspan="4"><button class="btn btn-default" onClick="location.href='userlist.action?userId=${user.id}'">返回</button></td>
							</c:if>
							<c:if test="${user.userType eq 3  }">
							<td colspan="6"><button class="btn btn-default" onClick="location.href='userlist.action?userId=${user.id}'">返回</button></td>
							</c:if>
							</tr>
							</tbody>
						</table>
						<!--评价详情start  -->	
						<table style="display:none"  class="table table-hover table-bordered" style="margin-top: 20px" id="alleva_table">
							<thead>
								<tr>
								<button id="back" style="display:none" class="btn btn-default" onClick="back()">返回</button>
								<button id="back2" style="display:none" class="btn btn-default" onClick="back2()">返回</button>
								</tr>
								<tr>
								<button style="display:none;" class="btn btn-info" id="searchByCount" onclick="chooseEvaByCount()">搜索</button>
								<input style="display:none;" class="form-control" placeholder="输入第  n 次课进行搜索" style="width:140px" id="inp_btn"> </input>
								</tr>
								<tr align="center" style="font-weight: bold">
									<td>序号</td>
									<td>课程名称</td>
									<td>教师</td>
									<td>评价人姓名</td>
									<c:if test="${user.userType ne 2 }">
									<td>评价分数</td>
									</c:if>
									<td>评价建议</td>
									<td>评价时间</td>
								</tr>
							</thead>
						</table>
						<!--评价详情end  -->
						<table style="display:none"  class="table table-hover table-bordered" style="margin-top: 20px" id="stus_table">
							<thead>
								<tr align="center" style="font-weight: bold">
									<td>序号</td>
									<td>姓名</td>
									<td>学号</td>
									<td>课程签到情况(签到数/总课程数)</td>
								</tr>
							</thead>
						</table>
					</div>
</div>
				</div>
			</div>
			<div class="col-md-2"></div>
		</div>
	</div>
	<script type="text/javascript">
		var userType = "${user.userType}";
		var baseUrl = "<%=baseUrl%>";
		window.onload = function(){
			hideOrShowOneTable("alleva_table",2);
		}
		//隐藏(隐藏)某个表格（1显示 2隐藏）
		function hideOrShowOneTable(tableName,type){
			if(type == 1){
				document.getElementById(tableName).removeAttribute("style");
			}else{
				document.getElementById(tableName).style.display = "none";
			}
		}
		function getStus(classId){
			hideOrShowOneTable("back",1);
			var classId = classId;
			$.ajax({
				type:"post",
				dataType:"json",
				url:baseUrl + "/user/getStuList.action?classId="+classId+"&id="+'${user.id}',
				success:function(res){
					addTR(res);
				},
				error:function(res){
					if(res.status == 200){
						addTR(res.responseText)
					}else{
						$.messager.popup("获取学生名单失败！(ajax error)");
					}
				}
			});
		}
		
		function back(){
			hideOrShowOneTable("user_table",1);
			hideOrShowOneTable("stus_table",2);
			document.getElementById("h2").style.display="none";
			document.getElementById("h1").removeAttribute("style");
			$('#stus_table tbody').remove();
			$('#alleva_table tbody').remove();
			hideOrShowOneTable("back",2);
		}
		
		function addTR(array){
			var j = 1;
			for(var i = 0; i < array.length; i++) {
				var tempStu = array[i];
				var tr = $("<tr>");
				tr.append($("<td>" + j + "</td>"));
				tr.append($("<td>" + tempStu.nickName + "</td>"));
				tr.append($("<td>" + tempStu.userCode + "</td>"));
				tr.append($("<td>" + tempStu.evaSum +"&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;"+tempStu.class_sum + "</td>"));
				$('#stus_table').append(tr);
				j++;
			}
			hideOrShowOneTable("user_table",2);
			hideOrShowOneTable("stus_table",1);
			document.getElementById("h1").style.display="none";
			document.getElementById("h2").removeAttribute("style");
		}
		
		function getAllEvaInfo(classId){
			hideOrShowOneTable("user_table",2);
			hideOrShowOneTable("alleva_table",1);
			
			hideOrShowOneTable("back2",1);
			document.getElementById("h1").style.display="none";
			document.getElementById("h2").style.display="none";
			document.getElementById("h3").removeAttribute("style");
			var classId = classId;
			$.ajax({
				type:"post",
				dataType:"json",
				url:baseUrl + "/user/getEvaList.action?classId="+classId+"&id="+'${user.id}',
				success:function(res){
					addTR2(res);
				},
				error:function(res){
					if(res.status == 200){
						addTR2(res.responseText)
					}else{
						$.messager.popup("获取学生名单失败！(ajax error)");
					}
				}
			});
		}
		
		function addTR2(array){
			hideOrShowOneTable("searchByCount",1);
			hideOrShowOneTable("inp_btn",1);
			document.getElementById("inp_btn").style.width="200px;";
			
			var j = 1;
			for(var i = 0; i < array.length; i++) {
				var temp = array[i];
				var tr = $("<tr data-i='evaDetail' id='tr["+i+"]'>");
				tr.append($("<td>" + j + "</td>"));
				tr.append($("<td>" + temp.className +"&nbsp;&nbsp;(第"+ temp.class_count+"次课)" + "</td>"));
				tr.append($("<td>" + temp.nickName + "</td>"));
				tr.append($("<td>" + temp.stuName + "</td>"));
				if(userType !=2 ){
					tr.append($("<td>" + temp.score + "</td>"));
				}
				tr.append($("<td>" + temp.remark + "</td>"));
				tr.append($("<td>" + temp.strTime + "</td>"));
				tr.append($("<input style='display:none' name='list["+i+"]' value='"+temp.class_count+"'></input>"));
				$('#alleva_table').append(tr);
				j++;
			}
		}
		
		function back2(){
			hideOrShowOneTable("searchByCount",2);
			hideOrShowOneTable("inp_btn",2);
			hideOrShowOneTable("user_table",1);
			hideOrShowOneTable("alleva_table",2);
			document.getElementById("h3").style.display="none";
			document.getElementById("h2").style.display="none";
			document.getElementById("h1").removeAttribute("style");
			$('#alleva_table tbody').remove();
			hideOrShowOneTable("back2",2);
			
		}
		
		function chooseEvaByCount(){
			var c = $("#inp_btn").val();
			$("#alleva_table tbody tr[data-i='evaDetail'] ").each(function(index,element){
				var class_count = $(this).find("input[name='list["+index+"]']").val();
				if(c != class_count){
					document.getElementById("tr["+index+"]").style.display="none";
				}else{
					document.getElementById("tr["+index+"]").removeAttribute("style");
				}
			});
		}
	</script>
</body>
</html>
